public class TravelMethod {
    // 按两次 Shift 打开“随处搜索”对话框并输入 `show whitespaces`，
// 然后按 Enter 键。现在，您可以在代码中看到空格字符。
    public class Main {
        public static void main(String[] args) {
            //1.抽象类TravelMethod是需要被强制继承的，创建的对象是子类对象，这里是SelfDrivingTravel类型的对象
            TravelMethod travelMethod =new SelfDrivingTravel(7, 1); //小轿车自驾7天游
            travelMethod.showTravelInfo();
            System.out.println("旅行费用：" + travelMethod.calculatePrice()+"元");
        }
    }

    //2.抽象类需要声明为abstract
    abstract class TravelMethod {
        protected int days;
        public TravelMethod(int days) {
            this.days = days;
        }
        public abstract void showTravelInfo();
        public abstract double calculatePrice();
    }

    class SelfDrivingTravel extends TravelMethod {
        private int carType; //自驾车型

        public SelfDrivingTravel(int days, int carType) {
            //3.调用父类的构造方法完成days的初始化，super(days)
            super(days);
            this.carType = carType;
        }

        //4.实现父类的抽象方法showTravelInfo
        public void showTravelInfo() {
            System.out.println("出行方式：自驾游");
            System.out.println("出行天数：" + days);
            System.out.println("车型：" + (carType == 1 ? "小轿车" : "越野车"));
        }

        public double calculatePrice() {
            double basePrice = carType == 1 ? 500.0 : 800.0;
            double pricePerDay = carType == 1 ? 50.0 : 80.0;
            return basePrice + days * pricePerDay;
        }
    }
}
